//
//  UserInfo.m
//  MyProject
//
//  Created by Pei on 16/7/5.
//  Copyright © 2016年 Xiaobo Pei. All rights reserved.
//

#import "UserInfo.h"
#import "YMUtil.h"



static UserInfo *instance;

@implementation UserInfo

+ (UserInfo*)getInstance;
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[UserInfo alloc] init];
    });
    return instance;
}

- (void)setMineUserInfo:(NSDictionary*)dic{
    dic = [YMUtil changeType:dic];
    
    NSUserDefaults *userT = [NSUserDefaults standardUserDefaults];
    [userT removeObjectForKey:User_Info];
    [userT synchronize];
    [userT setObject:dic forKey:User_Info];
}

- (void)setUserDic:(NSDictionary*)dic
{
    dic = [YMUtil changeType:dic];
    
    NSUserDefaults *userT = [NSUserDefaults standardUserDefaults];
    [userT removeObjectForKey:User_Default];
    [userT synchronize];
    [userT setObject:dic forKey:User_Default];
}

- (NSString *)getUseToken
{
    NSDictionary *tempDic = [[NSUserDefaults standardUserDefaults] objectForKey:User_Default];
    return [tempDic objectForKey:@"UserToken"];
}

- (NSString *)getUserID
{
    NSDictionary *tempDic = [[NSUserDefaults standardUserDefaults] objectForKey:User_Default];
    return [tempDic objectForKey:@"UserUid"];//[tempDic objectForKey:@"UserID"];
}

- (NSString*)getUserOrgCode
{
    NSDictionary *tempDic = [[NSUserDefaults standardUserDefaults] objectForKey:User_Default];
    NSString *ddd = [tempDic objectForKey:@"OrgCode"];
    if (ddd != nil && ddd.length > 0) {
        return ddd;
    }else{
       NSDictionary *tempDDD = [[NSUserDefaults standardUserDefaults] objectForKey:User_Info];
       return [tempDDD objectForKey:@"OrgCode"];
    }
    
}

- (NSDictionary*)getUserInfo
{
    NSDictionary *tempDic = [[NSUserDefaults standardUserDefaults] objectForKey:User_Default];
    return tempDic;
}

- (void)saveUserPrivilege:(NSDictionary*)dic{
    dic = [YMUtil changeType:dic];
    
    NSUserDefaults *userT = [NSUserDefaults standardUserDefaults];
    [userT removeObjectForKey:User_Privilege_Default];
    [userT synchronize];
    [userT setObject:dic forKey:User_Privilege_Default];
}

- (NSArray*)getUserPrivilege{
    NSUserDefaults *userT = [NSUserDefaults standardUserDefaults];
    NSDictionary *userDic = [userT objectForKey:User_Privilege_Default];
    return [userDic objectForKey:@"Privileges"];
}

@end
